package yunquan.wang.modules.base.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.jpa.domain.Specifications;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import yunquan.wang.base.dao.springdata.BaseRepository;
import yunquan.wang.base.service.impl.BaseServiceImpl;
import yunquan.wang.base.web.TreePojo;
import yunquan.wang.modules.base.dao.GroupInfoDao;
import yunquan.wang.modules.base.entity.GroupInfo;
import yunquan.wang.modules.base.service.GroupInfoService;

/**
 * GroupInfo Service层 实现
 * 
 * @author 王云权 wangyunquan@gmail.com 用生成器 生成于 2011-09-30 22:37
 * 
 */
@Service("groupInfoService")
@Transactional(value = "jpaTransaction")
public class GroupInfoServiceImpl extends BaseServiceImpl<GroupInfo> implements	GroupInfoService {
	@Resource 
	private GroupInfoDao groupInfoDao;
 
 

	public BaseRepository<GroupInfo, String> getDao() {
		return groupInfoDao;
	}

	private List<TreePojo> getSublevel(GroupInfo groupInfo,Integer level)
	{
		List<TreePojo> list = new ArrayList<TreePojo>();
//		 for(GroupInfo single:groupInfo.getChilds())
//		 {
//				TreePojo node=new TreePojo(single.getId(),groupInfo.getId(),single.getGroupName());
//				list.add(node);
//				if(single.getGroupType().getLevel()<level)
//				{
//					list.addAll(getSublevel(single,level));
//				}
//		 }
		return list;
	}
	
	public List<TreePojo> getgroupTree(final int level) {
		List<TreePojo> list = new ArrayList<TreePojo>();
		GroupInfo topGroupInfo = groupInfoDao.findOne("1");
		TreePojo top=new TreePojo(topGroupInfo.getId(),"0",topGroupInfo.getGroupName());
		list.add(top);
		list.addAll(getSublevel(topGroupInfo,level));
		return list;
	}

	@Override
	public List<GroupInfo> findAll(Specifications where) {
		return groupInfoDao.findAll(where);
	}
}
